package video.web;

import java.io.File;

import settings.GlobalSettings;
import util.HttpDownload;
import util.HttpDownloadThread;

public class VideoOnline {
	private ParserInterface parser;
	private String videoUrl;
	
	public VideoOnline(String videoUrl){
		this.videoUrl = videoUrl;
		
		if(videoUrl.contains("http://v.youku.com/v_show/"))
			parser = new Youku(videoUrl);
		else if(videoUrl.contains("http://www.tudou.com/programs/view/"))
			parser = new Tudou(videoUrl);
		else if(videoUrl.contains("http://www.56.com"))
			parser = new _56(videoUrl);
		else if(videoUrl.contains("http://video.sina.com.cn"))
			parser = new Sina(videoUrl);
		else if(videoUrl.contains("http://v.ku6.com/show"))
			parser = new Ku6(videoUrl);
		else
			parser = new Unknown();
	}
	
	/**
	 * 
	 * @return success
	 */
	public boolean download(){
		if( !parser.isReachable() )
			return false;
		String videoDir = GlobalSettings.videoFileFolder+"\\"+UrlParser.getSiteDomain(videoUrl)+"\\"+UrlParser.getVid(videoUrl)+" ";
		//new File(videoDir).mkdir();
		//System.out.println(parser.getFileUrl());
		if(null == parser.getFileUrl())	//unknown video site
			return false;
		HttpDownload httpDownload = new HttpDownload(parser.getFileUrl(), videoDir);
		return httpDownload.go();		
	}
}
